<?php

namespace App;

use App\Http\Services\FileManager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\MerchantMedicineArea
 *
 * @property int $id
 * @property int $merchant_id 商家id
 * @property string $name 专区名称
 * @property int $img_id 背景图片id
 * @property int $sort 排序:数字越小越前
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\MerchantMedicineArea onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereImgId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereMerchantId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\MerchantMedicineArea withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\MerchantMedicineArea withoutTrashed()
 * @mixin \Eloquent
 * @property int $status 展示状态0不显示，1显示
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereStatus($value)
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereDeletedAt($value)
 * @property string $desc 专区描述
 * @method static \Illuminate\Database\Eloquent\Builder|\App\MerchantMedicineArea whereDesc($value)
 */
class MerchantMedicineArea extends Model
{
    protected $table='merchant_medicine_area';
    use SoftDeletes;

    public static function getIndexSpecialArea($merchant_id){
        $data=self::whereStatus(1)
            ->whereMerchantId($merchant_id)
            ->orderBy('sort')
            ->get();
        if (count($data) > 0){
            foreach ($data as $item){
                $item->img_url=FileManager::getImgUrl($item->img_id);
            }
        }
        return $data ?? [];
    }

    public static function getAreaInfo($area_id){
        $data=self::whereId($area_id)->first();
        if ($data) {
            $data->img_url = FileManager::getImgUrl($data->img_id);
            $data->merchant_name = Merchant::getMerchantName($data->merchant_id);


        }
        return $data ?? [];
    }
}
